<template>
  <h1>员工列表综合练习</h1>
  <el-form style="width: 700px;margin: 0 auto;"label-width="80px">
    <el-form-item label="姓名">
      <el-input v-model="name" placeholder="请输入姓名"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="salary" placeholder="请输入工资" ></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="job" placeholder="请输入岗位" ></el-input>
    </el-form-item>
  </el-form>
  <el-button type="success" @click="submit" style="width: 100px">提交</el-button>

  <el-table :data="empArr" style="width: 650px;margin: 0 auto;">
    <el-table-column label="编号" type="index" width="80px" align="center"></el-table-column>
    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="工资" align="center"></el-table-column>
    <el-table-column prop="job" label="岗位" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
import index from "vuex";

const name = ref('');
const salary = ref('');
const job = ref('');
const empArr = ref([]);

const submit = () => {
  if (!name.value || !name.value.trim()
      || !salary.value || !salary.value.trim()
      || !job.value || !job.value.trim()){
    alert('请输入完整信息');
    return;
  }
  empArr.value.push({
    name:name.value,
    salary:salary.value,
    job:job.value
  })
  name.value='';
  salary.value='';
  job.value='';
}

const del = (index,row) => {
  if (confirm('你确定要删除“'+row.name+'”吗？')){
    empArr.value.splice(index,1);
  }
}

</script>


<style scoped>

</style>